<!--
 * @Descripttion: 联系人
 * @version: @ 1.0.0
 * @Author: 朱江洲
 * @Date: 2022-01-14 16:26:17
 * @LastEditors: 朱江洲
 * @LastEditTime: 2022-05-07 08:57:12
-->
<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%"
      ref="multipleTable"
      @selection-change="handleSelectionChange"
      height="490"
      row-key="id"
    >
      <template slot="empty" class="emptyBg">
        <img src="@/assets/images/empty.jpg" alt="" />
      </template>
      <el-table-column type="selection" width="55" reserve-selection>
      </el-table-column>
      <template v-for="(item, index) in switchShow">
        <el-table-column
          :key="index"
          :label="item.label"
          :prop="item.stage"
          :width="item.width"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
      </template>
    </el-table>
    <!-- 分页器 -->
    <el-pagination
      prev-text="上一页"
      next-text="下一页"
      background
      :page-size="pageSize"
      :page-sizes="[10, 20, 30, 40, 50, 100]"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageNum"
      layout=" ->,total, sizes, prev, pager, next, jumper "
      :total="total"
    >
    </el-pagination>
  </div>
</template>

<script>
import { getContactList } from "@/api/CRM";
export default {
  props: {
    drawerData: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      pageSize: 10,
      pageNum: 1,
      total: 0,
      tableData: [],
      contacts: [],
      // 控制表单的显示与隐藏
      switchShow: [
        {
          value: true,
          label: "姓名",
          stage: "name",
        },
        {
          value: true,
          label: "客户名称",
          stage: "crmName",
        },
        {
          value: true,
          label: "手机号码",
          stage: "phone",
          width: "120",
        },
        {
          value: true,
          label: "性别",
          stage: "sex",
        },
        {
          value: true,
          label: "职务",
          stage: "post",
        },
        {
          value: true,
          label: "微信",
          stage: "wechat",
        },
        {
          value: true,
          label: "是否关键决策人",
          stage: "leader",
          width: "120",
        },
        {
          value: true,
          label: "下次联系时间",
          stage: "education",
          width: "150",
        },
        {
          value: true,
          label: "备注",
          stage: "remark",
        },
        {
          value: true,
          label: "地址",
          stage: "address",
        },
        {
          value: true,
          label: "更新时间",
          stage: "updataTime",
        },
        {
          value: true,
          label: "负责人",
          stage: "directorName",
          width: "120",
        },
        {
          value: true,
          label: "创建人",
          stage: "createBy",
          width: "120",
        },
        {
          value: true,
          label: "创建时间",
          stage: "createTime",
          width: "200",
        },
      ],
    };
  },
  created() {
    this.getList();
  },

  methods: {
    handleSizeChange(val) {
      this.pageSize = val;
      this.pageNum = 1;
      this.getList();
    },
    //currentPage 改变时会触发
    handleCurrentChange(val) {
      this.pageNum = val;
      this.getList();
    },
    // 获取联系人列表
    getList(val) {
      getContactList({
        pageSize: this.pageSize,
        pageNum: this.pageNum,
        sceneId: val,
        identification: this.input,
      }).then((res) => {
        res.rows.map((item) => {
          if (item.sex == 1) {
            item.sex = "女";
          } else if (item.sex == 0) {
            item.sex = "男";
          }
          if (item.leader == 1) {
            item.leader = "是";
          } else if (item.leader == 2) {
            item.leader = "否";
          }
        });
        this.tableData = res.rows;
        if (this.drawerData !== {}) {
          this.tableData.forEach((item) => {
            if (
              this.drawerData.contacts !== undefined &&
              this.drawerData.contacts !== null
            ) {
              //判断条件，根据自己的项目进行添加
              this.$refs.multipleTable.toggleRowSelection(item);
            }
          });
        }
        this.total = res.total;
      });
    },
    // 表格前多选器
    handleSelectionChange(val) {
      this.contacts = [];
      this.contacts = val;
    },
  },
};
</script>

<style lang="less" scoped>
.el-pagination {
  margin-top: 24px;
  /deep/ .el-pagination__total {
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    margin-right: 25px;
  }
  /deep/ .btn-prev {
    width: 80px;
    height: 40px;
    text-align: center;
  }
  /deep/ .btn-next {
    width: 80px;
    height: 40px;
    text-align: center;
  }
  /deep/ .number {
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
  }
  /deep/ .el-input__inner {
    // width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
  }
  /deep/ .more {
    width: 40px;
    height: 40px;
    line-height: 40px;
    text-align: center;
  }
  /deep/ .el-pagination__jump {
    .el-input__inner {
      width: 40px;
      height: 40px;
    }
  }
}
</style>